package actions;

import java.rmi.Naming;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;

import javax.servlet.http.HttpServletRequest;

import donnees.Client;

import metier.IMetier;
import beans.*;

public class ActionValiderConnexion extends UnicastRemoteObject implements IAction{
	private static final long serialVersionUID = -6776715903739333439L;

	public ActionValiderConnexion() throws RemoteException {
		super();
	}

	@Override
	public String execute(HttpServletRequest req) throws Exception {
		IMetier metier=(IMetier)Naming.lookup("rmi://localhost:2000/ServeurMetier");
			ConnexionBean cb=new ConnexionBean(req.getParameter("mail"),req.getParameter("password"));
			String erreurmsg=cb.valider();
			req.setAttribute("erreurmsg", erreurmsg);
			if(erreurmsg.equals("")){
				req.getSession().setAttribute("leClient", (Client)metier.rechercherClientParMail(req.getParameter("mail")));
		    }
		return (String) req.getSession().getAttribute("currentPage");
	}
	
}
